package websocket

import (
	"flag"
	"fmt"
	"log"
	"net/http"
	"zhejianglab/gin-apiserver/pkg/logger"
	"zhejianglab/gin-apiserver/pkg/setting"
)

var addr = flag.String("addr", fmt.Sprint("0.0.0.0:", setting.WEBSocketPort), "http service address")

// RunWebsocket start websocket service
func RunWebsocket() {
	logger.Log.Info("Start Echo websocket service")
	flag.Parse()
	log.SetFlags(0)
	http.HandleFunc("/echo", wsHandler)
	go WriteBroadcastMessage()
	log.Fatal(http.ListenAndServe(*addr, nil))
}
